package cn.edu.neusoft.maxingxin231.yuejian06.Activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.maxingxin231.yuejian06.Bean.RegisterBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.LoginListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.AlterUserinfoModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class AlterUserinfoActivity extends BaseActivity {
    EditText tv_username,tv_password,tv_phone;
    Button btn_sub;
    ImageButton bt_back;
    ImageView img_user;
    String id,user_name,user_password,user_img;

    LoginListener<RegisterBean> registerBeanLoginListener = new LoginListener<RegisterBean>() {
        @Override
        public void onResponse(RegisterBean registerBean) {
            if(registerBean.getSuccess().equals("1")){
                Toast.makeText(AlterUserinfoActivity.this, "ok", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(AlterUserinfoActivity.this, "fail", Toast.LENGTH_SHORT).show();

        }
    };

    @Override
    void initView() {
        setLayout_file(R.layout.activity_alter_userinfo);
        img_user = (ImageView)findViewById(R.id.user_img);
        tv_username = (EditText)findViewById(R.id.tv_username);
        tv_password = (EditText)findViewById(R.id.tv_password);
        btn_sub = (Button)findViewById(R.id.btn_sub);
        bt_back = (ImageButton)findViewById(R.id.bt_back);

        id = getUser_id();
        user_name =getIntent().getStringExtra("user_name");
        user_password = getIntent().getStringExtra("user_password");
        tv_username.setText(user_name);
        tv_password.setText(user_password);
        user_img=getIntent().getStringExtra("user_img");
        Picasso.with(AlterUserinfoActivity.this).load("http://10.0.2.2:80/yuejian14/public/static/user_img/"+user_img).into(img_user);

    }

    @Override
    void initEvent() {
        btn_sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              AlterUserinfoModel alterUserinfoModel = new AlterUserinfoModel();
              alterUserinfoModel.updateName(id,tv_username.getText().toString(),registerBeanLoginListener);
              alterUserinfoModel.updatePassword(id,tv_password.getText().toString(),registerBeanLoginListener);
              finish();
            }
        });

        bt_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }


    @Override
    void initData() {

    }



    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
